<?php
class Mupload extends CI_Model{
    public $_url="";
    public $_path="";
    public function __construct() {
        parent::__construct();
        $this->_url=  base_url()."uploads/images/";
        $this->_path=  realpath(APPPATH."../uploads/images");
    }
    public function do_upload(){
        $config= array('upload_path'=>  $this->_path,
                       'allowed_types'=> 'gif|jpg|png',
                       'max_size'=>'2000' );
        $this->load->library("upload",$config);
        if(!$this->upload->do_upload("img")){
            $error = array($this->upload->display_errors());
        }
        else{
            $image_data = $this->upload->data();    
        }
        $config = array("source_image" => $image_data['full_path'],
                        "new_image" => $this->_path . "/thumbs",
                        "maintain_ration" => true,
                        "width" => '150',
                        "height" => "100");
                    $this->load->library("image_lib",$config);
                    $this->image_lib->resize();
    }
    public function get_images(){
        $file = scandir($this->_path);
        $file = array_diff($file, array('.', '..', 'thumbs'));
        
         $images = array();
        foreach($file as $img){
            $images[] = array("url"        => $this->_url . $img,
                              "thumb_url" => $this->_url . "" . $img);    
        }
        return $images;
    }
}
?>
